FROM fastdfs-common:1.0
LABEL Maintainer="shuaqiu <qiushaohua.bp@gmail.com>"

# Let's roll
RUN addgroup -S nginx && \
	adduser -D -S -h /var/lib/nginx -s /sbin/nologin -G nginx nginx && \
    mkdir -p /var/lib/nginx && \
    # 下载nginx 相关的资源
    wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz && \
    tar zxf pcre-8.42.tar.gz && \
    wget http://www.zlib.net/zlib-1.2.11.tar.gz && \
    tar xzf zlib-1.2.11.tar.gz && \
    git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1 && \
    wget http://nginx.org/download/nginx-1.15.0.tar.gz && \
    tar zxf nginx-1.15.0.tar.gz && \
    cd nginx-1.15.0 && \
    # 开始编译
    ./configure --prefix=/usr/share/nginx \
            --sbin-path=/usr/sbin/nginx \
            --modules-path=/usr/lib/nginx/modules \
            --conf-path=/etc/nginx/nginx.conf \
            --error-log-path=/var/log/nginx/error.log \
            --http-log-path=/var/log/nginx/access.log \
            --pid-path=/run/nginx.pid \
            --lock-path=/var/lock/nginx.lock \
            --user=nginx \
            --group=nginx \
            --build=Fastdfs-Nginx \
            --http-client-body-temp-path=/var/lib/nginx/body \
            --http-proxy-temp-path=/var/lib/nginx/proxy \
            --http-scgi-temp-path=/var/lib/nginx/scgi \
            --http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
            --with-pcre=../pcre-8.42 \
            --with-pcre-jit \
            --with-zlib=../zlib-1.2.11 \
            --add-module=../fastdfs-nginx-module/src/ \
            --with-compat \
            --with-threads \
            --with-http_addition_module \
            --with-http_auth_request_module \
            --with-http_dav_module \
            --with-http_flv_module \
            --with-http_mp4_module \
            --with-http_random_index_module \
            --with-http_realip_module \
            --with-http_slice_module \
            --with-http_sub_module \
            --with-http_stub_status_module \
            --with-http_v2_module \
            --with-http_secure_link_module \
            --with-stream \
            --with-stream_realip_module \
            --with-debug \
            --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' \
            --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' && \
    make && \
    make install && \
    cd .. && \
    # Cleaning up
    rm -Rf ./fastdfs-nginx-module ./pcre-8.42* ./zlib-1.2.11* ./nginx-1.15.0*

EXPOSE 8080

CMD [ "/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf" ]
